//package com.util;
//import org.lionsoul.ip2region.DataBlock;
//import org.lionsoul.ip2region.DbConfig;
//import org.lionsoul.ip2region.DbMakerConfigException;
//import org.lionsoul.ip2region.DbSearcher;
//import org.lionsoul.ip2region.Util;
//import org.springframework.core.io.ClassPathResource;
//
//import java.io.IOException;
//import cn.hutool.core.io.IoUtil;
//
///**
// * @author king
// * @date 2022/5/20 - 17:17
// */
//public class IpUtil {
//
//    private static final String dbRelativePath = "/ip2region.db";
//
//    private static byte[] dbData = null;
//
//    static {
//        dbData = IoUtil.readBytes(IpUtil.class.getResourceAsStream(dbRelativePath));
//    }
//
//
//    /**
//     * 根据 ip 获取地里位置
//     *
//     * @param ip
//     * @return
//     * @throws DbMakerConfigException
//     * @throws IOException
//     */
//    public static String getRegionFromIp(String ip) throws DbMakerConfigException, IOException {
//        DbSearcher searcher = new DbSearcher(new DbConfig(), dbData);
//        String region = null;
//        if (Util.isIpAddress(ip)) {
//            DataBlock dataBlock = searcher.memorySearch(ip);
//            region = dataBlock.getRegion();
//            return region;
//        }
//        return null;
//    }
//
//    public static void main(String[] args) throws DbMakerConfigException, IOException {
//        String[] ipArr = {"58.250.250.254", "204.124.181.253", "192.168.11.12", "127.0.0.1"};
//        for (int i = 0; i < ipArr.length; i++) {
//            System.out.println("------------------" + ipArr[i] + "----------------------------");
//            System.out.println(IpUtil.getRegionFromIp("192.168.11.12"));
//        }
//
//    }
//}
